package org.jeecg.modules.xl.wxbot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.xl.wxbot.entity.XlWxbotGroupMember;
import org.jeecg.modules.xl.wxbot.service.IXlWxbotGroupMemberService;
import org.jeecg.modules.xl.wxbot.vo.CallBackReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: xl_wxbot_group_member
 * @Author: jeecg-boot
 * @Date:   2025-02-12
 * @Version: V1.0
 */

@RestController
@RequestMapping("/slt/xlWxbotGroupMember")
@Slf4j
public class XlWxbotGroupMemberController extends JeecgController<XlWxbotGroupMember, IXlWxbotGroupMemberService> {
	@Autowired
	private IXlWxbotGroupMemberService xlWxbotGroupMemberService;
	
	/**
	 * 分页列表查询
	 *
	 * @param xlWxbotGroupMember
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "xl_wxbot_group_member-分页列表查询")
	@ApiOperation(value="xl_wxbot_group_member-分页列表查询", notes="xl_wxbot_group_member-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<XlWxbotGroupMember>> queryPageList(XlWxbotGroupMember xlWxbotGroupMember,
														   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
														   HttpServletRequest req) {
        QueryWrapper<XlWxbotGroupMember> queryWrapper = QueryGenerator.initQueryWrapper(xlWxbotGroupMember, req.getParameterMap());
		Page<XlWxbotGroupMember> page = new Page<XlWxbotGroupMember>(pageNo, pageSize);
		IPage<XlWxbotGroupMember> pageList = xlWxbotGroupMemberService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param xlWxbotGroupMember
	 * @return
	 */
	@AutoLog(value = "xl_wxbot_group_member-添加")
	@ApiOperation(value="xl_wxbot_group_member-添加", notes="xl_wxbot_group_member-添加")
	@RequiresPermissions("org.jeecg.modules.xl:xl_wxbot_group_member:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody XlWxbotGroupMember xlWxbotGroupMember) {
		xlWxbotGroupMemberService.save(xlWxbotGroupMember);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param xlWxbotGroupMember
	 * @return
	 */
	@AutoLog(value = "xl_wxbot_group_member-编辑")
	@ApiOperation(value="xl_wxbot_group_member-编辑", notes="xl_wxbot_group_member-编辑")
	@RequiresPermissions("org.jeecg.modules.xl:xl_wxbot_group_member:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody XlWxbotGroupMember xlWxbotGroupMember) {
		xlWxbotGroupMemberService.updateById(xlWxbotGroupMember);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "xl_wxbot_group_member-通过id删除")
	@ApiOperation(value="xl_wxbot_group_member-通过id删除", notes="xl_wxbot_group_member-通过id删除")
	@RequiresPermissions("org.jeecg.modules.xl:xl_wxbot_group_member:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		xlWxbotGroupMemberService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "xl_wxbot_group_member-批量删除")
	@ApiOperation(value="xl_wxbot_group_member-批量删除", notes="xl_wxbot_group_member-批量删除")
	@RequiresPermissions("org.jeecg.modules.xl:xl_wxbot_group_member:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.xlWxbotGroupMemberService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "xl_wxbot_group_member-通过id查询")
	@ApiOperation(value="xl_wxbot_group_member-通过id查询", notes="xl_wxbot_group_member-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<XlWxbotGroupMember> queryById(@RequestParam(name="id",required=true) String id) {
		XlWxbotGroupMember xlWxbotGroupMember = xlWxbotGroupMemberService.getById(id);
		if(xlWxbotGroupMember==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(xlWxbotGroupMember);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param xlWxbotGroupMember
    */
    @RequiresPermissions("org.jeecg.modules.xl:xl_wxbot_group_member:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, XlWxbotGroupMember xlWxbotGroupMember) {
        return super.exportXls(request, xlWxbotGroupMember, XlWxbotGroupMember.class, "xl_wxbot_group_member");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("org.jeecg.modules.xl:xl_wxbot_group_member:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, XlWxbotGroupMember.class);
    }


	@GetMapping(value = "/getMemsByGroupId")
	public Result<List<XlWxbotGroupMember>> getMemsByGroupId(@RequestParam(name="groupId",required=true) String groupId) {
		QueryWrapper<XlWxbotGroupMember> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("group_wxid",groupId);
		List<XlWxbotGroupMember> members = xlWxbotGroupMemberService.list(queryWrapper);
		return Result.OK(members);
	}

	@GetMapping(value = "/sendPayWxMsm")
	public Result<?> sendPayWxMsm(@RequestParam(name="orderCode",required=true) String orderCode,@RequestParam(name="totalRealAmount",required=true) Double totalRealAmount) throws InterruptedException {
		return xlWxbotGroupMemberService.sendPayWxMsm(orderCode,totalRealAmount);
	}
	@IgnoreAuth
	@RequestMapping(value = "/callbackapi")
	public Result<?> callbackapi(@RequestBody  CallBackReq callBackReq,HttpServletRequest request)   {
		return xlWxbotGroupMemberService.callbackapi(callBackReq);
	}
}
